#define _CRT_SECURE_NO_WARNINGS 1
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a1[9], book[9], COUNT = 0;
bool getSum(int* a) {
    int A = a[0], B = a[1], C = a[2];
    int DEF = a[3] * 100 + a[4] * 10 + a[5], GHI = a[6] * 100 + a[7] * 10 + a[8];
    if ((B * GHI + DEF * C) % (C * GHI) != 0) return false;
    if (A + (B * GHI + DEF * C) / (C * GHI) == 10) return true;
    return false;
}
void dfs(int step) {
    if (step == 9) {
        if (getSum(a1)) COUNT++;
        return;
    }
    for (int i = 0; i < 9; i++) {
        if (book[i] == 0) {
            book[i] = 1;
            a1[step] = i + 1;
            dfs(step + 1);
            book[i] = 0;
        }
    }
}
int main() {
    dfs(0);
    cout << COUNT << endl;
    return 0;
}